package org.opens.controller;

import org.opens.entity.MyBatisPerson;
import org.opens.service.MybatisPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/feign/mybatis/person")
public class MybatisPersonController {

    @Autowired
    private MybatisPersonService mybatisPersonService;

    @RequestMapping(value = "/{id}")
    public Map<String, Object> queryOneById(
            @PathVariable(value = "id", required = true) Integer id
    ) {
        Map<String, Object> result = new HashMap<>();
        try {
            MyBatisPerson data = mybatisPersonService.queryOneByPK(id);
            result.put("data", data);
            result.put("code", 200);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
        }
        return result;
    }

}
